<template>
    <div @click.self="hideCounselor" class="setting-page resume-page">
        <div @click="hideCounselor" class="setting-page-center">
            <div class="setting-page-left">
                <!--<div class="setting-nav">-->
                <!--<div class="setting-nav-title">简历管理</div>-->
                <!--<el-menu>-->
                <!--<el-menu-item v-for="(item, index) in navsList" :key="index">-->
                <!--<router-link :to="item.to">{{item.label}}</router-link>-->
                <!--</el-menu-item>-->
                <!--</el-menu>-->
                <!--</div>-->
                <left
                        class="setting-nav"
                        v-bind:entries="entries"
                        v-bind:active-entry="gc"
                        v-on:click-item="clickItem"
                ></left>
            </div>
            <div v-if="gc.g===0" class="setting-page-rigth">
                <all-resume v-if="gc.c===0"></all-resume>
                <platform-resume v-if="gc.c===1"></platform-resume>
            </div>

            <!--gc.g===1-->
            <resume-list
                    v-if="gc.g===2"
                    class="setting-page-rigth"
                    :brow="leftActiveCache"
                    :resume_list="resumeCache"
                    :total="resumeTotal"
                    :size="resumeSize"
                    @page-chage="resumePageChange"
            ></resume-list>
        </div>
        <div @click="showCounselor" class="resume-counselor">
            <div>
                <div style="text-align:center;margin:0 0 8px 0;">
                    <img src="../../assets/img/resume/guwen.png" alt>
                </div>
                <div>联系企业顾问</div>
            </div>
        </div>
        <div class="resume-counselor-show" v-if="counselorIndex">
            <job-consultant></job-consultant>
        </div>
    </div>
</template>

<script>
  import jobConsultant from '../../components/job-consultant'
  import allResume from './all-resume'
  import platformResume from './platform-resume'
  import Left from '../Left'
  import ResumeList from './ResumeList'
  import _g from '../../assets/utils/global'
  import * as _ from 'underscore'

  export default {
    name:'index-resume',
    props: {
      entries: {
        type: Array,
        default: function() {
          return [
            { group: '简历管理', children: ['全部', '平台推荐'] },
            { group: '沟通', children: ['人才沟通', '企业顾问'] },
            { group: '职位进展', children: ['待入职', '入职成功', '不合适'] }
          ]
        }
      }
    },
    data() {
      return {
        counselorIndex: false,
        title: '全部简历',
        time: 45,
        navsList: [
          { label: '全部', to: '/setting/binding' },
          { label: '平台推荐', to: '/setting/password' },
          { label: '隐私设置', to: '/setting/privacy' },
          { label: '银行账户', to: '/setting/bank' }
        ],
        gc: { g: 0, c: 0 },
        serverOptions: [],
        serverResumes: [],
        resumeCurrentPage: 1,
        resumeTotal: 0,
        resumeSize: 10
      }
    },
    methods: {
      resumePageChange(page) {
        console.log('page', page)
        this.resumeCurrentPage = page
      },
      hideCounselor() {
        this.counselorIndex = false
      },
      showCounselor() {
        this.counselorIndex = !this.counselorIndex
      },
      clickItem(g, c) {
        this.gc = { g: g, c: c }
        _g.getCache().gc = this.gc
        if (this.gc.g == 1 && this.gc.c == 0) {
          this.$router.push({ path: '/communication' })
        } else if (this.gc.g == 1 && this.gc.c == 1) {
          this.$router.push({ path: '/communication/Corporate' })
        }
        this.loadResumeData()
      },
      getState(c, s) {
        if (c === 0) {
          return '待入职'
        } else if (c === 1) {
          if (s === 0) {
            return '未过保'
          } else if (s === 2) {
            return '未过保已离职'
          } else {
            return '已过保'
          }
        } else if (c === 2) {
          return '不合适'
        }
      },
      //加载静态数据
      loadOptions: function() {
        _g.apiPost('/company/selectStaticData.do', { state: _.range(1, 44).join(',') })
          .then(res => {
            if (!_.isNull(res) && res.status === 0) {
              console.log('all options', res)
              this.serverOptions = res.data
            }
          })
      },
      //加载职位进展数据
      loadResumeData: function() {
        if (this.gc.g === 2) {
          let state = 2
          if (this.gc.c === 0) {
            state = 2
          } else if (this.gc.c === 1) {
            state = 3
          } else if (this.gc.c === 2) {
            state = 4
          }
          console.log('加载所有简历')
          _g
            .apiPost('/company/selectResumeByState.do', {
              currPageNo: this.resumeCurrentPage,
              pageSize: this.resumeSize,
              relationshipState: state
            })
            .then(res => {
              if (!_.isNull(res) && res.status === 0) {
                this.resumeTotal = res.data.total
                this.serverResumes = res.data.list
                console.log('所有简历', this.serverResumes)
              }
            })
        }
      },
      //加载
      formatEdu(o) {
        if (o.resumeJson.educationList) {
          if (o.resumeJson.educationList.length > 0) {
            if (o.resumeJson.educationList[0].academicStr) {
              return o.resumeJson.educationList[0].academicStr
            }
          }
        }
        return '学历未知'
      }
    },
    computed: {
      //选中的横眉
      leftActiveCache: function() {
        return this.entries[this.gc.g].children[this.gc.c]
      },
      //简历进展数据转换
      resumeCache: function() {
        return _.map(this.serverResumes, o => {
          return {
            sid: o.talentId,
            so: o,
            icon: o.imagePath,
            nick: o.userName,
            job: o.jobName,
            type: o.resumeJson.licenseList,
            salary: (o.tax === 0 ? '税前' : '税后') + o.salaryPerMonth + 'W/' + o.monthCount + '年',
            age: (o.age ? o.age : '未知') + '岁',
            work_period: o.workDayStr ? o.workDayStr + '年' : '工作年限未知',
            education: this.formatEdu(o),
            state: this.getState(this.gc.c, Number(o.ensureState)),
            attach: o.resumeJson.attachResume,
            showReportQ: o.report === 1
          }
        })
      }
    },
    components: {
      jobConsultant,
      allResume,
      platformResume,
      Left: Left,
      ResumeList: ResumeList
    },
    created() {
      this.loadOptions()
    },
    mounted() {
      this.gc = _g.getCache().gc
    }
  }
</script>

<style lang="scss" scoped>
    .resume-index-root {
        width: 100vw;

        display: flex;
        flex-direction: column;
        align-items: center;
        background: #f2f2f2;
    }

    .content_cls {
        display: flex;
        justify-items: center;
    }

    .resume_left_cls {
        margin-top: 21px;
    }

    .resume_list_cls {
        margin-left: 19px;
    }

    .nav_cls {
        margin-top: 20px;
        margin-bottom: 232px;
    }
</style>
